﻿using System;
using System.Collections;
using System.Globalization;
using System.Linq;
using System.Windows.Data;

namespace MalRec.Base.Converter
{
    public class JoinListToStringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            if (!(value is IList) || value == null)
            {
                //throw new InvalidOperationException("Parameter needs to be of IList");
                return "-";
            }
            var eh = value as IList;
            var res = (from object i in eh
                       select i.ToString()).ToArray();

            if (res.Length == 0)
            {
                return "-";
            }
            else
            {
                string eehehehehheheh = ", ";
                if (parameter != null)
                {
                    eehehehehheheh = parameter.ToString();
                }

                return string.Join(eehehehehheheh, res);
            }
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}